import grok
from zope import interface
from interfaces import IBook

class Book(grok.Model):
    """ 
    A book with a title and a list of creators.

      >>> book = Book('Web Component Development with Zope 3', creators=['Philipp von Weitershausen'])
      >>> book.title
      'Web Component Development with Zope 3'
      >>> book.creators
      ['Philipp von Weitershausen']

    Book objects also have methods used only for indexing itself on the site catalog:

      >>> book.creatorsSet()
      set(['philipp von weitershausen'])
      >>> book.searchableText()
      'Web Component Development with Zope 3 Philipp von Weitershausen'

    """
    interface.implements(IBook)
    title = ''
    creators = []

    def __init__(self, title='', creators=[]):
        super(Book, self).__init__()
        self.title = title
        self.creators = creators

    def creatorsSet(self):
        return set([creator.strip().lower() for creator in self.creators])

    def searchableText(self):
        return self.title + ' ' + ' '.join(self.creators)

class Edit(grok.EditForm):
    pass

class Index(grok.DisplayForm):
    pass
